package com.haoshuang.zhouzhoubang.utils

import android.content.res.AssetManager
import android.media.MediaPlayer
import com.mufeng.libs.utils.context
import java.io.IOException

object MediaPlayUtils {

    /**
     * 播放assets音频
     * @param path: assets文件夹下的文件名字
     */
    fun playAudio(path: String){
        val player = MediaPlayer()
        val assetManager: AssetManager = context.resources.assets
        try {
            val fileDescriptor = assetManager.openFd(path)
            player.setDataSource(
                fileDescriptor.fileDescriptor,
                fileDescriptor.startOffset,
                fileDescriptor.getLength()
            )
            player.prepare()
            player.start()
        } catch (e: IOException) {
            e.printStackTrace()
        }
    }

    /**
     * 播放抢单成功音频
     */
    fun playTakeOrderSuccess(){
        playAudio("take_order_success.mp3")
    }

    /**
     * 播放提交验收成功音频
     */
    fun playSubmitAcceptanceSuccess(){
        playAudio("submit_order_success.mp3")
    }

}